package org.example.liuy.service.session;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class RandomSessionKeyGenerator implements SessionKeyGenerator {
    private static final String ALPHA_NUMERIC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final int LENGTH = 7;

    @Override
    public String generate() {
        Random random = ThreadLocalRandom.current();
        char[] buf = new char[LENGTH];
        for (int i = 0; i < LENGTH; i++) {
            buf[i] = ALPHA_NUMERIC.charAt(random.nextInt(ALPHA_NUMERIC.length()));
        }
        return new String(buf);
    }
}
